<article class="card">
    <div style="margin-bottom:2rem;">
        <div style="display:flex;align-items:center;gap:1rem;margin-bottom:1rem;flex-wrap:wrap;">
            <span class="hero-badge">
                <span>状态</span>
                <span class="feed-status {{ mistake.status }}">{{ mistake.get_status_display }}</span>
            </span>
            {% if mistake.is_archived %}
                <span class="pill">📦 已归档</span>
            {% endif %}
        </div>
        
        <h2 style="margin:0 0 1rem 0;">{{ mistake.title }}</h2>
        
        <div class="meta-grid">
            <div class="meta-item">
                <span class="meta-label">学生</span>
                <span class="meta-value">{{ mistake.student.username }}</span>
            </div>
            <div class="meta-item">
                <span class="meta-label">指导老师</span>
                <span class="meta-value">
                    {% if mistake.assigned_teacher %}
                        {{ mistake.assigned_teacher.username }}
                    {% else %}
                        <em style="color:var(--text-tertiary);font-weight:400;">未指派</em>
                    {% endif %}
                </span>
            </div>
            <div class="meta-item">
                <span class="meta-label">创建时间</span>
                <span class="meta-value">{{ mistake.created_at|date:"Y-m-d H:i" }}</span>
            </div>
            <div class="meta-item">
                <span class="meta-label">最后更新</span>
                <span class="meta-value">{{ mistake.updated_at|date:"Y-m-d H:i" }}</span>
            </div>
        </div>
        
        <div class="action-group" style="margin-top:1.5rem;">
            <a class="button small secondary" href="{% url 'learning:mistake_list' %}">
                ← 返回列表
            </a>
            {% if user.is_student and mistake.student_id == user.id and mistake.status == mistake.Status.DRAFT %}
                <form method="post" action="{% url 'learning:mistake_submit' mistake.pk %}" class="inline-form">
                    {% csrf_token %}
                    <button type="submit" class="button small">提交老师批阅</button>
                </form>
                <form method="post" action="{% url 'learning:mistake_delete' mistake.pk %}" class="inline-form" onsubmit="return confirm('确认删除这条草稿吗？此操作不可恢复。');">
                    {% csrf_token %}
                    <input type="hidden" name="next" value="{% url 'learning:mistake_list' %}">
                    <button type="submit" class="button small danger">删除草稿</button>
                </form>
            {% elif user.is_student and mistake.status == mistake.Status.SUBMITTED %}
                <span class="pill">⏳ 等待老师批阅</span>
            {% elif user.is_student and mistake.status == mistake.Status.RESOLVED %}
                <span class="pill success">✓ 老师已反馈</span>
            {% endif %}
            {% if user.is_student and mistake.student_id == user.id and mistake.status == mistake.Status.RESOLVED %}
                {% if mistake.is_archived %}
                    <form method="post" action="{% url 'learning:mistake_restore' mistake.pk %}" class="inline-form">
                        {% csrf_token %}
                        <input type="hidden" name="next" value="{{ mistake.get_absolute_url }}">
                        <button type="submit" class="button small secondary">恢复显示</button>
                    </form>
                {% else %}
                    <form method="post" action="{% url 'learning:mistake_archive' mistake.pk %}" class="inline-form">
                        {% csrf_token %}
                        <input type="hidden" name="next" value="{% url 'learning:mistake_list' %}">
                        <button type="submit" class="button small secondary">归档该错题</button>
                    </form>
                {% endif %}
            {% endif %}
        </div>
    </div>
    
    <div>
        <h4 class="section-heading">📝 题目内容</h4>
        <div class="content-block">{{ mistake.question|linebreaks }}</div>
        {% if mistake.question_image %}
        <div style="margin-top:1rem;">
            <img src="{{ mistake.question_image.url }}" alt="题目图片" style="max-width:100%;border-radius:var(--radius-lg);border:1px solid var(--border-subtle);box-shadow:var(--shadow-sm);">
        </div>
        {% endif %}
        
        {% if mistake.solution_attempt %}
        <h4 class="section-heading">✏️ 我的解答</h4>
        <div class="content-block">{{ mistake.solution_attempt|linebreaks }}</div>
        {% if mistake.solution_attempt_image %}
        <div style="margin-top:1rem;">
            <img src="{{ mistake.solution_attempt_image.url }}" alt="解题过程图片" style="max-width:100%;border-radius:var(--radius-lg);border:1px solid var(--border-subtle);box-shadow:var(--shadow-sm);">
        </div>
        {% endif %}
        {% endif %}
        
        {% if mistake.correct_solution %}
        <h4 class="section-heading">✅ 正确思路</h4>
        <div class="content-block">{{ mistake.correct_solution|linebreaks }}</div>
        {% endif %}
        
        {% if mistake.reflection %}
        <h4 class="section-heading">💡 反思总结</h4>
        <div class="content-block">{{ mistake.reflection|linebreaks }}</div>
        {% endif %}
        
        {% if mistake.teacher_feedback %}
        <h4 class="section-heading">👨‍🏫 老师反馈</h4>
        <div class="content-block" style="background:var(--warning-light);border-color:rgba(234,179,8,0.3);">
            {{ mistake.teacher_feedback|linebreaks }}
        </div>
        {% endif %}
    </div>
</article>
